#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
	int val;
	struct node* next;
}node;
node* newnode(int x)
{
	node* new = (node*)malloc(sizeof(node));
	new->val = x;
	new->next = NULL;
	return new;
}
int main()
{
	node* s1 = newnode(1);
	node* s2 = newnode(2);
	node* s3 = newnode(3);
	node* s4 = newnode(4);
	node* s5 = newnode(5);
	node* s9 = newnode(9);
	node* s8 = newnode(8);
	node* s7 = newnode(7);
	s1->next = s2;
	s2->next = s3;
	s3->next = s4;
	s4->next = s5;
	s9->next = s8;
	s8->next = s7;
	s7->next = s4;
	node* cur = s1;
	node* pur = s9;
	int a = 1;
	int b = 1;
	while (cur->next)
	{
		cur = cur->next;
		a++;
	}
	while (pur->next)
	{
		pur = pur->next;
		b++;
	}
	if (cur!=pur)
	{
		return NULL;
	}
	int s = abs(a - b);
	node* long_node = s1;
	node* short_node = s9;
	if (b > a)
	{
		 long_node = s9;
		 short_node = s1;
	}
	while (s)
	{
		long_node = long_node->next;
		s--;
	}
	int flag = 0;
	while (short_node->val != long_node->val)
	{
		short_node = short_node->next;
		long_node = long_node->next;
		flag = 1;
	}
	if (flag == 1)
	{
		printf("%d", long_node->val);
	}
	return 0;
}